package com.prft.rms.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.prft.rms.entity.Employee2;

/**
 * This class just used for some hibernate feature test.
 * @author cairns.ma
 *
 */
@Repository
public class EmployeeDao2 {

	@Autowired
	private SessionFactory sessionFactory;

	public List<Employee2> getAll() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Employee2.class);
		List<Employee2> employeeList = criteria.list();
		return employeeList;
	}

	public void BatchUpdate() {
		Session session = sessionFactory.getCurrentSession();
		for(int i =0; i<100000; i++){
			Employee2 employee = new Employee2("tom" + i);
			session.save(employee);
			if (i % 20 == 0) {
				session.flush();
				session.clear();
			}
		}
		session.close();
	}


	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
